// 引入mockjs
const Mock = require('mockjs')

const List = []
const count = 100

// ID 标题 类型 重要性 积分 操作人 操作日期 状态 图片
for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: '@increment',
    timestamp: +Mock.Random.date('T'),
    operator: '@first',
    title: '@ctitle(5, 10)',
    'importance|1': ['主线','支线'],
    'type|1': ['全校','学院','班级','社团'],
    'status|1': ['published', 'draft'],
    point:'@integer(1,5)',
    display_time: '@datetime',
    img:'@image'
  }))
}

module.exports = [
  {
    url: '/XinMiao_MS/task/list',
    type: 'get',
    response: config => {
      const { img,status,point,importance, type, title, page = 1, limit = 20, sort } = config.query

      let mockList = List.filter(item => {
        if (img && item.img !== img) return false
        if (status && item.status !== status) return false
        if (importance && item.importance !== importance) return false
        if (type && item.type !== type) return false
        if (title && item.title!== title) return false
        if (point && item.point !== point) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },

  {
    url: '/XinMiao_MS/task/detail',
    type: 'get',
    response: config => {
      const { id } = config.query
      for (const task of List) {
        if (task.id === +id) {
          return {
            code: 20000,
            data: task
          }
        }
      }
    }
  },

  {
    url: '/XinMiao_MS/task/create',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  {
    url: '/XinMiao_MS/task/update',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]

